<?php
	session_start();
	if (isset($_SESSION['username']))
	{
		$login = true;
		$usr = $_SESSION['username'];
	}
	else
	{
		$login = false;
		$usr = "";
	}
	$radio = $_POST['tipe'];
	$string = $_POST['searchtext'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="search.css" />
<link rel="stylesheet" type="text/css" href="style/footoo.css" />
<link rel="stylesheet" type="text/css" href="style/ftheader.css" />
<link rel="stylesheet" type="text/css" href="style/ftfooter.css" />
<link rel="stylesheet" type="text/css" href="style/ftcommoncontent.css" />
<script type="text/javascript" src="script/search.js"></script>
<script type="text/javascript" src="script/visopt.js"></script> 
<title>Foo-Too</title>
</head>

<body>
    <div id="headerwrapper">
		<div id = "headerbgfx"></div>
        <div id="footooheader">
        	<div id="footoologo">
            	<a href="#"></a>
            </div>
            <div id="loginarea">
				<?php
					if (!$login)
					{
						echo '<form action="php/auth.php" method="post">';
						echo '	<table id="inputLogin">';
						echo '	<tr>';
						echo '		<td class="iltext">Username</td><td><input type="text" name="usr"></td>';
						echo '		</tr><tr>';
						echo '		<td class="iltext">Password</td><td><input type="password" name="pass"></td>';
						echo '	</tr><tr>';
						echo '	<td></td><td><input type="submit" value="login" /></td>';
						echo '	</tr>';
						echo '</table>';
						echo '</form>';
					}
					else
					{
						echo '<a href = "php/logout.php"  class="out">Log out</a>';
					}
				?>
			</div>
        </div>
        <div id="footoomenu">
            <ul>
				<?php
					if ($login)
					{
					    echo '<li><a href="home.php" class="current">Home</a></li>';
						echo '<li><a href="profile.php?'.$_SESSION['username'].'">Profil</a></li>';
						echo '<li><a href="wall.php?'.$_SESSION['username'].'">Wall</a>';
						echo '</li><li><a href="fts.php">Photos</a>';
						echo '</li><li><a href="message.php?'.$_SESSION['username'].'">Message</a></li>';
					}
					else{
					    echo '<li><a href="" class="current">Welcome..</a></li>';
					}
				?>
            </ul>
        </div>
    </div>
    <div id="headermirror">
    	<div id="searchbox">
            <form action="search.php" method="post">
            	<select class="searchselect" name="tipe">
                	<option value="user">User</option>
                	<option value="photo">Photo</option>
                </select>
                <div class="searchbutton">
                    <input id="searchbutton" type="submit" value="" />
                </div>
                <div class="searchtext">
                <input id="searchtext" class="searchtext" type="text" name="searchtext" value="search" onfocus="filledTrue(this.id, 'search')" onblur="filledFalse(this.id, 'search')" />
            	</div>
            </form>		
        </div>
	</div>
    <div id="contentwrapper">
    	<div id="contento">
		<table cellspacing = "10" align = "center">
			<tr>
				<td class= "user" valign = "top">
					<div class="box"><?php
					if ($radio == 'photo')
						echo 'Photo(s)';
					else
						echo 'User(s)';
					?></div>
					<?php
						require_once 'php\database.php';
						if (!$login)
						{
							$e1 = $e2 = $e3 = $e4 = "";
						}
						else
						{
							if ($radio == 'photo')
							{
								$e1 = $e2 = $e3 = $e4 = "";
							}
							else
							{
								$e1 = '<div class="button180" onclick="add_followee(';
								$e2 = ');">Follow</div>';
								
								if ($_SESSION['role']==1)
								{
									$e3 = '<div class="button180" onclick="Block(';
									$e4 = ');">Block</div>';
								}
								else
									$e3 = $e4 = "";
							}
						}
						if ($radio == 'photo')
						{
							$hasil = database::query("SELECT IDFoto, Username,FileFoto FROM foto WHERE username LIKE %$string%");
							if ($string == '')
								$hasil = database::query("SELECT * FROM foto");
							else
								$hasil = database::query("SELECT * FROM foto  WHERE filefoto LIKE '%$string%'");
							if (mysql_num_rows($hasil)>0)
							{
								while ($baris = mysql_fetch_row($hasil))
								{
									$namafile = 'users/'.$baris[1].'/'.$baris[2];
									echo '<a href = "detail.php?id='.$baris[0].'">';
									echo '<img src = "'.$namafile.'" width = 100 height = 100/>';
									echo '</a>';
								}
							}
							else
								echo '<a href = "home.php">Kosong</a>';
						}
						else
						{
							if ($string == '')
								$hasil = database::query("SELECT * FROM user WHERE Role = 0");
							else
								$hasil = database::query("SELECT * FROM user  WHERE user.Username LIKE '%$string%' AND Role=0");
							if (mysql_num_rows($hasil)>0)
							{
								echo '<table><tr>';
								$count = 0;
								while ($baris = mysql_fetch_row($hasil))
								{
									if ($baris[8]==NULL)
										$namafile = 'images/bg-photo.png';	
									else
									{
										$hasil2 = database::query("SELECT * FROM foto WHERE IDFoto=$baris[8]");
										$baris2 = mysql_fetch_row($hasil2);
										$namafile = 'users/'.$baris2[1].'/'.$baris2[2];
									}
									echo '<td><a href = "'.$namafile.'"><img src="'.$namafile.'" width = 100 height = 100/></a>&nbsp&nbsp&nbsp&nbsp';
									$namafile = 'users/'.$baris2[1].'/'.$baris2[2];
									
									if (strlen($baris[3])>10)
										$baris[3]=substr($baris[3], 0, 10).'...';
									echo '<br/><a href="profile.php?'.$baris[0].'">'.$baris[3].'</a><br/>';
									if ($usr != $baris[0])
									{
										if ($e1!='')
										{
											echo '<br/>';
											echo $e1."'".$baris[0]."', '".$_SESSION['username']."'".$e2;
										}
										if ($e3!='')
										{
											echo '<br/>
											
											
											
											';
											echo $e3."'".$baris[0]."'".$e4;
										}
									}
									echo '<br/></td>';
									if (++$count%5==0)
										echo "<tr></tr>";
								}
								echo '</tr></table>';
							}
							else
								echo 'Kosong';
						}
					?>
					<form method="post" action="php/add_followee.php" name="add">
						<input type="hidden" name ="sembunyi" value="" id="add"/>
						<input type="hidden" name ="sembunyi2" value="" id="add2"/>
					</form>
					<form method="post" action="php/block.php" name="block">
						<input type="hidden" name ="sembunyi" value="" id="block"/>
					</form>
				</td>
			</tr>
		</table>
        </div>
    </div>
		
	    <div id="footerwrapper">
    	<div id="footer">
            <div id="footerleft"><br/>
            	ft, ft logoes are trademark of ft company. <br/>
            	Copyright 2010 by : <br/>
                13508011 - M. Albadr Lutan Nasution <br/>
                13508019 - Gregorius Ronny Kaluge <br/>
                13508099 - Alwi Alfiansyah Ramdan <br/>
            </div>
            <div id="footermiddle">
            	
            </div>
            <div id="footerright">
            	
            </div>
        </div>
    </div>
</body>
</html>
